package com.rst.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.rst.model.Student;


/**
 * @author SivaLabs
 *
 */
@Component("studentFormValidator")
public class StudentFormValidator implements Validator
{
	@Override
	public boolean supports(@SuppressWarnings("rawtypes") Class clazz)
	{
		return Student.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object model, Errors errors)
	{
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name","required.name", "Name is required.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dob","required.dob", "dob is required.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "address","required.address", "address is required.");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email","required.email", "email is required."); 
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "mobile","required.mobile", "mobile is required."); 
	
		Student student = (Student) model;
/*		if(student.getUserId() != 24){
			errors.rejectValue("mobile", "notmatch.mobile");
		}
*/	}

}
